package com.controller.admin;

import com.business.bean.Role;
import com.business.bean.layuiBean.ResultPage;
import com.business.bean.layuiBean.VoPage;
import com.business.service.RoleService;
import com.controller.annotation.LogMenthodName;
import com.controller.commen.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author 张子艺
 * @packge com.controller.admin
 * @data 2019-01-10 10:33
 * @project Currency
 */
@Controller
@RequestMapping("/role")
public class RoleController extends BaseController {
       @Autowired
    RoleService roleService;

    /**
     * 角色管理主页面
     * @return
     */
    @RequestMapping(value = "/main.html", method = RequestMethod.GET)
    public String main() {
        return "system/role";
    }

    /**
     * 添加角色页面
     * @return
     */
    @RequiresPermissions("button:角色管理添加")
    @RequestMapping(value = "/roleAdd.html", method = RequestMethod.GET)
    public String roleAdd() {
        return "system/role_add";
    }

    /**
     * 角色表格查询
     * @param voPage
     * @return
     */
    @RequestMapping(value = "/findRole", method = RequestMethod.GET)
    @ResponseBody
    public ResultPage<Role> findRole(VoPage voPage) {
        return  roleService.findRoleByPage(voPage);
    }


    /**
     * 角色所有查询
     * @param voPage
     * @return
     */
    @RequestMapping(value = "/findRoleAll", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> findRoleAll(VoPage voPage) {
        return  roleService.findRoleAll(voPage);
    }


    /**
     * 添加角色  AJAX
     * @param
     * @return
     */
    @LogMenthodName(name = "添加角色AOP")
    @RequestMapping(value = "/insertRole", method = RequestMethod.POST)
    @ResponseBody
    @RequiresPermissions("button:角色管理添加")
    public Map<String, Object> insertRole(String roleName, String menuId) {
        return  roleService.insertRole(roleName,menuId);
    }


    /**
     * 删除角色  AJAX
     * @param
     * @return
     */
    @LogMenthodName(name = "删除角色AOP")
    @RequestMapping(value = "/delRole", method = RequestMethod.POST)
    @ResponseBody
    @RequiresPermissions("button:角色管理删除")
    public Map<String, Object> delRole(  Long roleId) {
        return  roleService.delRole(roleId);
    }


}
